package com.example.ggpicturegg.test;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.ImageView;

import com.example.ggpicturegg.Mysql_com.Mysql_tool;
import com.example.ggpicturegg.R;
import com.example.ggpicturegg.ftpUD.UpAndDown;
import com.example.ggpicturegg.imageinfo.UserNameAndImageInfo;
import com.example.ggpicturegg.imageinfo.UserNameAndNameinfo;
import com.example.ggpicturegg.tool.BlobAndBytes;
import com.example.ggpicturegg.tool.Loaddata;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;

public class ImagePath extends AppCompatActivity {

    private String ss;
    private PathDao pathDao;
    private Handler mainHandler;
    private ImageView Tv_imageView;
    private Bitmap bitmap;
    private InputStream inputStream;
    private byte[] bytes;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_path);
        Tv_imageView = findViewById(R.id.image123);
        mainHandler = new Handler(getMainLooper()) ; //获取主线程

        pathDao = new PathDao();
       // mainHandler = new Handler(getMainLooper());      //获取主线程
        bytes = null;


        String s = "SELECT id,image_name,user_name,title,collection,`describe` from imageinfo,likeinfo WHERE likeinfo.user_like_name='luzn' AND likeinfo.image_like_id=imageinfo.id";
        System.out.println("--- ("+s+") ----");



/*              //          上传和下载功能完成
        new Thread(new Runnable() {
            @Override
            public void run() {
                String s = UpAndDown.ftpUpload("/storage/emulated/0/Pictures/科比.jpg","科比.jpg",999);
                String ss = null;
                try {
                    ss = UpAndDown.ftpDown("/storage/emulated/0/Pictures/","No.999-科比.jpg","kebe.jpg");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                System.out.println("---------ftpUpload----------  "+s+" ---------------------");
                System.out.println("------- --ftpDown----------   "+ss+" ---------------------");
            }
        }).start();
*/
/*
        new Thread(new Runnable() {
            @Override
            public void run() {

                //pathDao.SelectPathInsertIntoDB(2,"C:\\Users\\51083\\Pictures\\test\\123456.txt");   // 写进数据库
                //String s = UpAndDown.ftpUpload("/sdcard/Pictures/","IMG_20210902_091610.jpg");
                //String t = UpAndDown.ftpUpload("/sdcard/Pictures/","IMG_20210908_091525.jpg");

               // String s = UpAndDown.ftpDown("/sdcard/Pictures/","9_image.jpg","9_image.jpg");
                //System.out.println("1234564616416434664345     is  " +s);


                inputStream = UpAndDown.ftpLook("8_image.jpg",1);

                try {
                    bytes = BlobAndBytes.readStream(inputStream);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                bitmap = BlobAndBytes.getPicFromBytes(bytes);
                mainHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if(bitmap!=null){
                            Tv_imageView.setImageBitmap(bitmap);
                        }
                    }
                });



            }
        }).start();
        */



        //  图片展示
        new Thread(new Runnable() {
            @Override
            public void run() {

                bitmap =  Loaddata.getImage("8_image.jpg",1);
                mainHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        Tv_imageView.setImageBitmap(bitmap);
                    }
                });
            }
        }).start();



        Mysql_tool tool = new Mysql_tool();

        new Thread(new Runnable() {
            @Override
            public void run() {
                UserNameAndImageInfo item=null;
                item=tool.find_is_like("xueli",110);
                if(item!=null){
                    System.out.println(item.getId()+" ----------------------------------- "+item.getName());
                }
                else{
                    System.out.println(" ------- UserNameAndImageInfo kongkongkong -----------------");
                }

                UserNameAndNameinfo item2 = null;
                item2=tool.find_is_care("luzn","xueli");
                if(item2!=null){
                    System.out.println(item2.getCare_name()+" ----------------------------------- "+item2.getBe_care_name());
                }
                else{
                    System.out.println(" ------- UserNameAndNameinfo  kongkongkong -----------------");
                }
            }
        }).start();


    }


}